package tuanke;

import java.util.List;

import com.todofun.business.tuanke.ApplyRecordService;
import com.todofun.business.tuanke.CampaignService;
import com.todofun.business.tuanke.LessonService;
import com.todofun.business.tuanke.vo.ApplyRecord;
import com.todofun.business.tuanke.vo.Campaign;
import com.todofun.business.tuanke.vo.Lesson;
import com.todofun.common.app.BusinessException;

public class testTuankeManagement extends TuankeBaseTest{
	public void testPublishCampaign(){
		CampaignService campaignService = new CampaignService();
		
		Lesson lesson = this.getLessonInDB(); 
		Campaign campaign = new Campaign();
		campaign.setLessonId(lesson.getId());
		campaign.setName("NO.28 JAVA TRAIN");
		campaign.setStartDate("2011-7-24");
		campaign.setEndDate("2011-08-24");
		campaign.setMaxNumber(120);
		campaign.setDescription("Nesest by CIC.New teacher New experience...");
		campaign.setDiscountComments("Purchase price : 2000");
		
		campaignService.save(campaign);
		assertNotNull(campaign.getId());
		
		campaign = campaignService.getCampaignByID(campaign.getId());
		campaign.setName("New NO.28 JAVA TRAIN");
		campaign.setPublishedTime("xxx");
		campaign.setIsPublished(true);
		campaign.setStatus("xxx");
		campaignService.edit(campaign);
		campaign = campaignService.getCampaignByID(campaign.getId());
		
		assertEquals("New NO.28 JAVA TRAIN",campaign.getName());
		assertFalse("Published 不可以被UI修改",campaign.getIsPublished());
		assertFalse("PublishedTime 不可以被UI修改","xxx".equals(campaign.getPublishedTime()));
		assertFalse("Status 不可以被UI修改","xxx".equals(campaign.getStatus()));
		
		campaignService.publishCampaign(campaign.getId());
		try {
			campaignService.edit(campaign);
			assertFalse(true);
		} catch (Exception e) {
			assertEquals("发布之后不可修改",e.getMessage());
		}
		
		List allPublisingCampaign = campaignService.listAllPublisingCampaign();
		assertEquals(1,allPublisingCampaign.size());
		
		campaignService.toggleInfo(campaign.getId());
		
		allPublisingCampaign = campaignService.listAllPublisingCampaign();
		assertEquals(0,allPublisingCampaign.size());
		
		try {
			campaignService.delCampaign(campaign.getId());
			assertFalse(true);
		} catch (Exception e) {
			assertEquals("发布之后不可删除",e.getMessage());
		}
		
	}
	
	public void testEntry() {
		
	}
	
	public void testReport(){
	}
}
